#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
using namespace std;
int n, k, tmp;
int main()
{
	cin >> n;
	//int arr[n][n];
	int arr[1000][1000];
	for (int i = 0;i < n;i++)
	{
		for (int j = 0;j <= i;j++)
		{
			cin >> arr[i][j];
		}
	}
	for (int i = n - 1;i > 0;i--)
	{
		for (int j = i;j > 0;j--)
		{
			if (arr[i][j] >= arr[i][j - 1])
				arr[i - 1][j - 1] += arr[i][j];
			else
				arr[i - 1][j - 1] += arr[i][j - 1];
		}
	}
	cout << arr[0][0];
}